package com.yimo.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * Author: yuyong
 * Date: 2018-03-28 上午10:16
 * Description: swagger相关配置
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    //可以注入多个doket，也就是多个版本的api，可以在看到有三个版本groupName不能是重复的，v1和v2是ant风格匹配，配置文件
    @Bean
    public Docket api() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yimo"))
                .paths(PathSelectors.any())
                .paths(Predicates.not(regex("/error.*")))
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("爬虫")
                .termsOfServiceUrl("www.yimobuy.com/productapi")
                .contact(new Contact("jsm","","jinsimin@yimo8.com"))
                .version("v0.01")
                .build();
    }

}
